import axios from "axios";
export default {
  namespaced:true,
  actions:{
    addWang:function(conText,value) {
      if (value.name.startsWith('王')) {
        conText.commit('ADD_PERSION',value)
      }else {
        alert('包含王吗？')
      }
    },
    addForServe:function(conText,value) {
      axios.get('https://api.uixsj.cn/hitokoto/get').then(
        (response)=>{
          console.log(response.data);
          conText.commit('ADD_SERVE',response.data)
        },
        (error)=>{
          console.log(error)
        }
      )
      // conText.commit('ADD_PERSION',value)
    }
  },
  mutations:{
    ADD_PERSION:function(state,value) {
      state.persionList.unshift(value)
    },
    ADD_SERVE:function (state,value) {
      state.serverStr = value
    }
  },
  state:{
    persionList:[
      {id:'001',name:'admin'},
      {id:'002',name:'张三'}
    ],
    serverStr:''
  },
  getters:{
    firstName(state) {
      return state.persionList[0].name
    }
  }
}